﻿@using Projectmanagement.Models
@{
    ViewBag.Title = "Customer";
}
<style type="text/css">
    #Customer
    {
        margin-top: 9px;
    }
    .delBtn
    {
        margin-left: 10px;
        border: 1px solid #eee;
        padding: 1px 5px 3px 5px;
        background: #B3B4B1;
        color: #fff;
        font-size: 14px;
        text-decoration: none;
    }
</style>
@(Html.Telerik().Grid<_Customer>()
                .Name("Customer")
    .DataKeys(keys => { keys.Add(item => item.ID); })
    .ToolBar(toolBar => toolBar.Template(
                @<text> 供应商表： <a class="t-button t-grid-add" href="/Customer?Customer-mode=insert">新增记录</a>
</text>
                ))
        .DataBinding(dataBinding =>
        {
            dataBinding.Ajax()
            .Select("_SelectIndex", "Customer")
            .Insert("_InsertAjaxEditing", "Customer")
            .Update("_SaveAjaxEditing", "Customer")
            .Delete("_DeleteAjaxEditing", "Customer");
        })
            .Columns(columns =>
            {
                columns.Bound(item => item.CustomerName).Width(100);
                columns.Bound(item => item.ContactName).Width(100);
                columns.Bound(item => item.ContactPlane).Width(100);
                columns.Bound(item => item.ContactMobile).Width(100);
                columns.Bound(item => item.ContactEmail).Width(100);
                columns.Bound(item => item.ContactTitle).Width(100);


                columns.Command(commands =>
                {
                    commands.Edit();
                    commands.Delete();
                }).Title("操作").Width(200);
            }).Resizable(r => r.Columns(true))



            .DetailView(view => view.ClientTemplate(
                Html.Telerik().TabStrip()
                    .Name("TabStrip_<#= ID #>")
                    .SelectedIndex(0)
                    .Items(items =>
                    {
                        items.Add().Text("会议厅").HtmlAttributes(new { style = "width:90px;text-align: center" }).Content(
                            Html.Telerik().Grid<_Chamber>()
                                .Name("Chamber_<#= ID #>")
                                .HtmlAttributes(new { @class = "gridMeeting" })
                                .DataKeys(keys => { keys.Add(item => item.ID); })
                                .ClientEvents(events => events.OnEdit("onEdit")
                                .OnDataBinding("Grid_onDataBinding"))
                                .ToolBar(toolBar => toolBar.Template(
                                    @<text>
<table>
    <tr>
        <td style="width: 30%">
            会议厅格局: @Html.DropDownList("txtChamberStructure", new[] { new SelectListItem() { Text = "分割", Value = "1" }, new SelectListItem() { Text = "不可分割", Value = "2" } }, "请选择......", new { style = "width:165px;" })
            &nbsp;&nbsp;
            <input type="button" name="txtName" id="btnSearch" value="查询" style="width: 50px"
                onclick="btnSearch()" />
        </td>
    </tr>
    <tr>
        <a class="t-button t-grid-add" href="/Chamber?Chamber-mode=insert">新增记录</a></tr>
</table>
</text>
                                    ))
                                .DataBinding(dataBinding =>
                                {
                                    dataBinding.Ajax()
                                        .Select("_SelectIndex", "Chamber", new { conferenceid = "<#= ID #>" })
                                        .Insert("_InsertAjaxEditing", "Chamber", new { conferenceid = "<#= ID #>" })
                                        .Update("_SaveAjaxEditing", "Chamber", new { conferenceid = "<#= ID #>" })
                                        .Delete("_DeleteAjaxEditing", "Chamber", new { conferenceid = "<#= ID #>" });
                                })
                                .Columns(columns =>
                                {
                                    columns.Bound(item => item.Name).Width(100);
                                    columns.Bound(item => item.ChamberStructureFormat).Width(100);
                                    columns.Bound(item => item.ChamberStructureDesc).Width(100);
                                    columns.Bound(item => item.PostDesc).Width(100);
                                    columns.Bound(item => item.ChamberFloorQuantity).Width(100);
                                    columns.Bound(item => item.ChamberDesc).Width(100);
                                    columns.Bound(item => item.ChamberStorey).Width(100);
                                    columns.Bound(item => item.ChamberSize).Width(100);
                                    columns.Bound(item => item.ChamberArea).Width(100);

                                    columns.Bound(item => item.MarketPrice).Width(100);
                                    columns.Bound(item => item.ReferencePrice).Width(100);
                                    columns.Bound(item => item.MeetingArea).Width(100);

                                    columns.Command(commands =>
                                    {
                                        commands.Edit();
                                        commands.Delete();
                                    }).Title("操作").Width(200);
                                })
                                .Editable(editing => editing.Mode(GridEditMode.PopUp))
                                .Pageable(paging => paging.Style(GridPagerStyles.Status).PageOnScroll(true))
                                .Scrollable()
                                .Sortable()
                                .ToHtmlString()

                            );
                        items.Add().Text("距离").HtmlAttributes(new { style = "width:90px;text-align: center" }).Content(
                        Html.Telerik().Grid<_LocationDistance>()
                            .Name("LocationDistance_<#= ID #>")
                            .HtmlAttributes(new { @class = "gridMeeting" })
                            .DataKeys(keys => { keys.Add(item => item.ID); })
                            .ClientEvents(events => events.OnEdit("onEdit")
                            )
                            .ToolBar(toolBar => toolBar.Template(
                                @<text> <a class="t-button t-grid-add" href="/LocationDistance?LocationDistance-mode=insert">
                                    新增记录</a>
</text>
                                ))
                            .DataBinding(dataBinding =>
                            {
                                dataBinding.Ajax()
                                    .Select("_SelectIndex", "LocationDistance", new { conferenceid = "<#= ID #>" })
                                    .Insert("_InsertAjaxEditing", "LocationDistance", new { conferenceid = "<#= ID #>" })
                                    .Update("_SaveAjaxEditing", "LocationDistance", new { conferenceid = "<#= ID #>" })
                                    .Delete("_DeleteAjaxEditing", "LocationDistance", new { conferenceid = "<#= ID #>" });
                            })
                            .Columns(columns =>
                            {
                                columns.Bound(item => item.TrafficType).Width(100);
                                columns.Bound(item => item.TargetLocation).Width(100);
                                columns.Bound(item => item.Distance).Width(100);
                                columns.Bound(item => item.SpendTime).Width(100);

                                columns.Command(commands =>
                                {
                                    commands.Edit();
                                    commands.Delete();
                                }).Title("操作").Width(200);
                            })
                            .Editable(editing => editing.Mode(GridEditMode.PopUp))
                            .Pageable(paging => paging.Style(GridPagerStyles.Status).PageOnScroll(true))
                            .Scrollable()
                            .Sortable()
                            .ToHtmlString()

                        );
                    })
                            .ToHtmlString()
                    ))

            .Editable(editing => editing.Mode(GridEditMode.PopUp))
                            .Pageable(item => item.Style(GridPagerStyles.Status).PageSize(50).PageOnScroll(true)).Scrollable(s => s.Height(600)).Scrollable(c => c.Height(600))
    .Resizable(resizing => resizing.Columns(true))
                            .Sortable().ClientEvents(s => s.OnEdit("onEdit"))
        )
<script type="text/javascript">
    function onEdit(e) {
        var selec = $("#Country").val();
        var url = "/Customer/GetCitySelectListItems/" + $("#Country").val() + "/";
        $("#City").find("option").remove();
        $.getJSON(url, { 'countryID': selec }, function (data) {
            $.each(data, function (i, item) {
                $("<option></option>").val(item["ID"]).text(item["Name"]).appendTo($("#City"));
            });
        });
    }

    function btnSearch() {
        $(".gridMeeting").data("tGrid").ajaxRequest();
    };

    function Grid_onDataBinding(e) {
        var ChamberStructure = $("#txtChamberStructure").val();
        e.data = {
            ChamberStructure: ChamberStructure

        };
    }
    function OnComplete(e) {
        $(".t-button.t-button-icontext.t-upload-action").remove();
    }

</script>
